package com.jsgt.greekfire.ui.coin.drawers

import android.app.Dialog
import android.content.Intent
import android.text.TextUtils
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.fhx.core.base.BaseActivity
import com.fhx.core.goToActivity
import com.fhx.core.utils.ToastUtils
import com.jsgt.greekfire.R
import kotlinx.android.synthetic.main.activity_payment_settings.*
import org.jetbrains.anko.intentFor

class PaymentSettingsListActivity : BaseActivity() {
    var wechatAnimationFinished: Boolean = true
    var alipayAnimationFinished: Boolean = true
    var wechatHeight: Int = 0
    var alipayHeight: Int = 0
    var right_iv: ImageView? = null
    var ivDialogClosed: ImageView? = null
    var tvDlWechat: TextView? = null
    var tvDlAlipay: TextView? = null
    var tvTitle: TextView? = null
    override fun getLayoutId(): Int = R.layout.activity_payment_settings
    override fun main() {
        right_iv = findViewById(R.id.right_iv)
        tvTitle = findViewById(R.id.title_tv)
        tvTitle?.text = resources.getString(R.string.payment_settings)
        val w = View.MeasureSpec.makeMeasureSpec(
            0,
            View.MeasureSpec.UNSPECIFIED
        )
        val h = View.MeasureSpec.makeMeasureSpec(
            0,
            View.MeasureSpec.UNSPECIFIED
        )
        llWechat.measure(w, h)
        llAlipay.measure(w, h)
        wechatHeight = llWechat.getMeasuredHeight()
        alipayHeight = llAlipay.getMeasuredHeight()
        val width: Int = llWechat.getMeasuredWidth()
        rllWechatContent.setOnClickListener { v ->

            if (!wechatAnimationFinished)
                return@setOnClickListener
            val animation = ExpandAnimation(llWechat, wechatHeight.toLong())
            llWechat.startAnimation(animation)

        }
        llWechat.setOnClickListener { v ->
            startActivity(
                this!!.intentFor<BindingPaymentSettingActivity>()
                    .putExtra("type", "wechat")
                    .putExtra("name", tvName?.text.toString())
                    .putExtra("account", tvAccountNumber?.text.toString())
                    .putExtra("ivcode", R.mipmap.ic_launcher)
                    .putExtra("unlink", true)
            )
        }
        llAlipay.setOnClickListener { v ->

            startActivity(
                this!!.intentFor<BindingPaymentSettingActivity>()
                    .putExtra("type", "alipay")
                    .putExtra("name", tvName?.text.toString())
                    .putExtra("account", tvAccountNumber?.text.toString())
                    .putExtra("ivcode", R.mipmap.ic_launcher)
                    .putExtra("unlink", true)
            )
        }
        rllAlipayContent.setOnClickListener { v ->

            if (!alipayAnimationFinished)
                return@setOnClickListener
            val animation = ExpandAnimation(llAlipay, alipayHeight.toLong())
            llAlipay.startAnimation(animation)

        }
        right_iv?.setOnClickListener { v ->
            show1();
        }

    }

    private fun show1() {
        val button1Dialog: Dialog = Dialog(this, R.style.DialogTheme)
        val view: View = LayoutInflater.from(this).inflate(R.layout.dialog_content_normal, null)
        button1Dialog.setContentView(view)
        var layoutParams: ViewGroup.LayoutParams = view.layoutParams
        layoutParams.width = resources.displayMetrics.widthPixels
        view.layoutParams = layoutParams
        button1Dialog.window!!.setGravity(Gravity.BOTTOM)
        button1Dialog.window!!.setWindowAnimations(R.style.main_menu_animStyle)
        button1Dialog.show()

        ivDialogClosed = view.findViewById(R.id.ivDialogClosed)
        tvDlWechat = view.findViewById(R.id.tvDlWechat)
        tvDlAlipay = view.findViewById(R.id.tvDlAlipay)
        ivDialogClosed?.setOnClickListener { v ->
            button1Dialog.dismiss()
        }
        tvDlWechat?.setOnClickListener { v ->
            startActivity(
                this!!.intentFor<BindingPaymentSettingActivity>()
                    .putExtra("type", "wechat")
            )
            button1Dialog.dismiss()
        }
        tvDlAlipay?.setOnClickListener { v ->
            startActivity(
                this!!.intentFor<BindingPaymentSettingActivity>()
                    .putExtra("type", "alipay")
            )
            button1Dialog.dismiss()
        }

    }

}